/**
 * https://leetcode.cn/problems/the-number-of-weak-characters-in-the-game/submissions/589545080/
 * 1996. 游戏中弱角色的数量
 * medium 2024.12.26
 * 单调栈
 */

class Solution {
public:
    int numberOfWeakCharacters(vector<vector<int>>& properties) {
        sort(properties.begin(),properties.end());
        int n=properties.size();
        int t=properties[n-1][1];
        int ans=0;
        int m=0;
        for(int i=n-2;i>=0;--i){
            if(properties[i][0]!=properties[i+1][0])
                m=t;
            if(properties[i][1]<m)
                ans++;
            t=max(t,properties[i][1]);
        }
        return ans;
    }
};